function dataset = traffic2mat(opt, datapath, daylist, senlist)

% parse a set of continuous days data into mat

% datapath: the path where the .traffic files exist. It is also where
%           the unzipped file being placed.
% daylist is a listing all days
% senlist is a list of sensor numbers

% Example: 
%dataset=traffic2mat(1, 'C:/MN_Data/extract', {'20110718' '20110719' 
    %'20110720' '20110721' '20110722' '20110723' '20110724'}, 
    %{'700' '701' '702' '703' '704' '705' '706' '707' '708' '709' '710' 
    %'711' '712' '713' '714' '292' '293' '294' '295' '296' '297' '298' 
    %'299' '470' '471' '472' '473' '196' '197' '198' '120' '200' '201' 
    %'202' '116' '492' '493' '494'});

path7zip = '"C:/Program Files/7-Zip/7z"';

dataset.numdays = length(daylist);
dataset.numsens = length(senlist);
dataset.days = daylist;
dataset.sens = senlist;
flow = zeros(dataset.numsens, dataset.numdays * 2880);
occu = zeros(size(flow));
% flags records if each sensor file is successfully read
% 1 yes; 0 no
flags_v = zeros(dataset.numsens, dataset.numdays);
flags_c = zeros(dataset.numsens, dataset.numdays);

for days = 1:dataset.numdays
    for sens = 1:dataset.numsens
        unzip_a_sensor(daylist{days}, senlist{sens}, datapath, datapath, path7zip);
        [v, flag] = read_single_v30([datapath '/' daylist{days}], senlist{sens});
        flags_v(sens, days) = flag;
        flow(sens, 2880*(days-1)+1 : 2880*days) = v';
        
        [c, flag] = read_single_c30([datapath '/' daylist{days}], senlist{sens});
        flags_c(sens, days) = flag;
        occu(sens, 2880*(days-1)+1 : 2880*days) = c';
    end
end
dataset.v = flow;
dataset.c = occu;
dataset.flagv = flags_v;
dataset.flagc = flags_c;

% acquire sensors location (lon, lat)
load('data/MNsensors');

numsens = dataset.numsens;
lat = zeros(numsens, 1);
lon = zeros(numsens, 1);
for idx = 1:numsens
    index = find(MNsensors.sno==str2double(senlist{idx}) );
    if ~isempty(index)
        lat(idx, 1) = MNsensors.latitude(index);
        lon(idx, 1) = MNsensors.longitude(index);
    else
        lat(idx, 1) = -999;
        lon(idx, 1) = -999;
    end
end

dataset.latlist = lat;
dataset.lonlist = lon;

filename = ['data/dataset' datestr(date())];
save(filename, 'dataset');
% parse all certain days in a time period (i.e. all Wed. between 
%[n,s] = weekday('19-Dec-2011');
%n=2 s= Mon